File Upload | 您所在的位置:网站首页 › A way to upload an image file to the product by api › File Upload |
File Upload Because Selenium cannot interact with the file upload dialog, it provides a way to upload files without opening the dialog. If the element is an input element with type file, you can use the send keys method to send the full path to the file that will be uploaded. WebElement fileInput = driver.findElement(By.cssSelector("input[type=file]")); fileInput.sendKeys(uploadFile.getAbsolutePath()); driver.findElement(By.id("file-submit")).click(); View full example on GitHub file_input = driver.find_element(By.CSS_SELECTOR, "input[type='file']") file_input.send_keys(upload_file) driver.find_element(By.ID, "file-submit").click() View full example on GitHub IWebElement fileInput = driver.FindElement(By.CssSelector("input[type=file]")); fileInput.SendKeys(uploadFile); driver.FindElement(By.Id("file-submit")).Click(); View full example on GitHub file_input = driver.find_element(css: 'input[type=file]') file_input.send_keys(upload_file) driver.find_element(id: 'file-submit').click View full example on GitHub await driver.findElement(By.id("file-upload")).sendKeys(image); await driver.findElement(By.id("file-submit")).submit(); View full example on GitHubMove Code ```java import org.openqa.selenium.By import org.openqa.selenium.chrome.ChromeDriver fun main() { val driver = ChromeDriver() driver.get("https://the-internet.herokuapp.com/upload") driver.findElement(By.id("file-upload")).sendKeys("selenium-snapshot.jpg") driver.findElement(By.id("file-submit")).submit() if(driver.pageSource.contains("File Uploaded!")) { println("file uploaded") } else{ println("file not uploaded") } } ```Last modified November 17, 2023: Upgrade to Docsy 0 7 2 (#1529) (48f43616907) |
CopyRight 2018-2019 实验室设备网 版权所有 |